package com.itserver.utils;

import com.itserver.utils.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
//    @Value("${file.upload-dir}")
//    private String uploadDir;
//    @Value("${file.base-url}")
//    private String baseUrl;

    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Autowired
    private UploadFile uploadFile;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String uploadDir = uploadFile.getUploadDir();
        String baseUrl = uploadFile.getBaseUrl();

        registry.addResourceHandler(baseUrl+"**")
                .addResourceLocations("file:" + uploadDir);
    }

    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**").excludePathPatterns("/captcha","/login","/register","/uploadFile/*","/static/**");
    }


}
